detecting and piercing shadow dom fix + unit tests for recorder and workflow #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1) This script resolves the previous issue where the workflow could not detect or pierce the Shadow DOM.
Shadow DOM Detection
I updated content.ts to handle all edge cases. On page load, the script monkey-patches the browser’s attachShadow method so that any element attempting to create a closed shadow root instead creates an open one. It also registers event listeners inside these roots. Additionally, it wraps customElements.define to trace future custom element constructors, scans the existing DOM for open roots, and observes the document for newly added shadow DOMs.
This enables the recorder to capture clicks, inputs, keypresses, scrolls, and navigation events as if they occurred in the regular DOM.
Shadow DOM Piercing
Piercing the Shadow DOM works similarly. We can’t rely on content.ts during workflow execution because the browser runs without the extension (as intended). Instead, I inject a nearly identical script each time a workflow is launched. This script monkey-patches all shadow roots from closed to open, enabling access by Playwright.
2) Pytests:
I've added one test for the recorder component
I've added two tests for the workflow component
Playwright cannot pierce closed Shadow DOMs directly (reference), so this approach is likely the only viable solution.
These tests are a work in progress, but I’m opening this PR to request early feedback so I can finalize the implementation. I believe this update is critical to improving the robustness of workflow-use.